import link from 'axios';
import {To} from 'ls-base-lib';
import {type MasApiType} from "ls-base-lib/dist/src/library/AwaitTo/ToResult/types";

export const axiosInstance = link.create();

export const to = new To<MasApiType, 1>(x => {
  if (x.data.code === 200)
    return x.data.data;
  else
    to.showMessage(x.data.info);
});

if ('baseAPI' in window)
  axiosInstance.defaults.baseURL = baseAPI;
else
  console.warn('未配置baseAPI，请检查');

const token = localStorage.getItem('TOKEN');
if (token)
  axiosInstance.defaults.headers.common.token = token;
else
  console.warn('未检测到token，请检查');
